package com.venus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.venus.entity.Consultant;
import com.venus.entity.Tool;
import com.venus.service.ToolService;
import com.venus.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 分配表 前端控制器
 * </p>
 *
 * @author Venus
 * @since 2020-06-08
 */
@Controller
@RequestMapping("/tool")
public class ToolController {
    @Resource
    private ToolService toolService;

    @RequestMapping("/select")
    public Object select(){
        Tool tool=toolService.getOne(new QueryWrapper<Tool>().eq("is_auto",1));
        return tool;
    }

    @RequestMapping("/isAuto")
    public Object updateOpen(Tool tool) {

        if (tool.getIsAuto().equals("1")) {
            tool.setIsAuto("0");
            boolean update = toolService.updateById(tool);
            if (update == true) {
                return new Result(0, "已关闭自动分配");
            } else {
                return new Result(2, "出问题了，刷新试试吧！");
            }
        } else {
            tool.setIsAuto("1");
            boolean update = toolService.updateById(tool);
            if (update == true) {
                return new Result(1, "已开启自动分配");
            } else {
                return new Result(2, "出问题了，刷新试试吧！");
            }
        }
    }
}
